#include "headfile.h"


struct PID speed={175,20,0};
struct PID turn={0};

unsigned char steer_flag=0;
//****************������Ҫ**************
unsigned char flag_task=0;


//=======================云台============================
double meicix=0;//用于微分
double meiciy=0;

float goal_dutyyaw=0;//用于微分判断什么时候停止
float goal_dutypitch=0;

int move_stop_flagyaw=0;
int move_stop_flagpitch=0;
int cloud_state=0;
int cloud_time=0;
int clude_flag=0;
int pause_flag=0;


float renwusanj8_yaw=0.0;
float renwusanj8_pitch=0.0;

float j8renwusi_yaw=0.0;
float j8renwusi_pitch=0.0;
double weifenyaw=0.0;
double weifenpitch=0.0;

int renwusi_stop=0;
int renwusi_zhongzhi=0;

char select_point=0;
float float_yaw_duty=0;
float float_pitch_duty=0;

double ceshi=0.0;
// {yaw,pitch}
int zuobiao[5][2]=
{
	{907,377},
	{950,415},
	{866,421},
	{867,342},
	{954,338}
};

int task3[5][2]=
{
	{909,382},
	{950,416},
	{916,415},
	{915,371},
	{949,370}
};
//=========================================================

unsigned char config_flag = 0;//���ڽ������UI����ģʽ��Ϊ�˽�ʡ������Դռ���Ҳ��뻻����ͻ�����ᵽ������Ϊȫ�ֱ���ʹ��

const float UNIT_ROUND[3] = {1 , 10, 100}; //��λ�߶ȱ任
const char  SHOW_UNIT[][5] = {"1   ", "10  " , "100 "};
//��ʾ����
char buf[30]={0};

//�����key.hʹ��
signed char _last_desk=-1; //ֻ�����ж��Ƿ�������
signed char _now_mod  = 1;          //��ǰ����


unsigned short base_spd=20;
int16 spwm=0;



const unsigned char CursorPosition[14][2]=
{
				{0,1},
				{0,2},
				{0,3},
				{0,4},
				{0,5},
				{0,6},
				{0,7},
				
				{64,1},
				{64,2},
				{64,3},
				{64,4},
				{64,5},
				{64,6},
				{64,7}	
};

const unsigned char xianshishuzu[14][2]=
{
				{8,1},
				{8,2},
				{8,3},
				{8,4},
				{8,5},
				{8,6},
				{8,7},
				
				{72,1},
				{72,2},
				{72,3},
				{72,4},
				{72,5},
				{72,6},
				{72,7}	
};
//ʹ���ݣ�����������ʱ��1��num֮��ѭ����
//����ֵ��_now_mod
signed char _Key_Control(short num)  //ֻ���������������if�밴��ѡģʽ
{
	if(config_flag==0&&LEFT_IN){_now_mod--;};
	if(config_flag==0&&RIGHT_IN){_now_mod++;};
	if(_now_mod>num)_now_mod=1;
	if(_now_mod<1)  _now_mod=num;
	return _now_mod;
}
static void Round_Param(signed char* num,signed char min,signed char max)
{
    if (*num > max)
    {
        *num = (*num - max) % (max - min + 1) + min-1;
    }
    else if (*num < min)
    {
        *num = max - (min - *num) % (max - min + 1) + 1;
    }
}
static void Cursor_Pos(const unsigned char cp[][2],unsigned char now_pos)
{
    static signed char last_pos=0;
    oled_p6x8str(cp[last_pos][0],cp[last_pos][1]," ");
    oled_p6x8str(cp[now_pos][0],cp[now_pos][1],"*");

    last_pos=now_pos;
}

void Main_UI(void)
{
		_STATIC_DESK_HEAD(_desk4)
	 //�ž�̬��ʾ���ݣ�
		sprintf((char *)buf,"yaw_dt:");SHOW(0,1,buf);
		sprintf((char *)buf,"pitch_:");SHOW(0,2,buf);
	 _STATIC_DESK_END(_desk4)
	 //�Ŷ�̬��ʾ���ݣ�
	  sprintf((char *)buf,"x:%d  y:%d  ",dx,dy);SHOW(0,0,buf);
		sprintf((char *)buf,"%f    ",task4_yaw);SHOW(40,1,buf);
		sprintf((char *)buf,"%f    ",task4_pitch);SHOW(40,2,buf);
		sprintf((char *)buf,"y_p=%f  ",yaw_p);SHOW(0,3,buf);
		sprintf((char *)buf,"y_d=%f  ",yaw_d);SHOW(0,4,buf);
		sprintf((char *)buf,"p_p=%f  ",pitch_p);SHOW(0,5,buf);
		sprintf((char *)buf,"p_d=%f  ",pitch_d);SHOW(0,6,buf);
//		if(UP_IN){yaw_p+=0.01;}
//		if(DOWN_IN){yaw_p-=0.01;}
//		if(LEFT_IN){pitch_p+=0.01;}
//		if(RIGHT_IN){pitch_p-=0.01;}
//		sprintf((char *)buf,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c    ",jieshoushuzu[0],jieshoushuzu[1],
//		jieshoushuzu[6],jieshoushuzu[7],jieshoushuzu[8],jieshoushuzu[9],jieshoushuzu[10],
//			jieshoushuzu[2],jieshoushuzu[3],jieshoushuzu[4],jieshoushuzu[5],
//		jieshoushuzu[11],jieshoushuzu[12],jieshoushuzu[13],jieshoushuzu[14]);SHOW(0,6,buf);
}

void Motor_Test(void)
{
//		_STATIC_DESK_HEAD(_desk2)
//	 //�ž�̬��ʾ���ݣ�
//		sprintf((char *)buf,"<Motor Test>");SHOW(0,0,buf);
//	 _STATIC_DESK_END(_desk2)
	 //�Ŷ�̬��ʾ���ݣ�
//		sprintf((char *)buf,"right_speed:%.2f ",R_spd);SHOW(0,1,buf);
//		sprintf((char *)buf,"left_speed:%.2f  ",L_spd);SHOW(0,2,buf);
//		sprintf((char *)buf,"right_pwm:%.2f   ",right_pwm);SHOW(0,3,buf);
//		sprintf((char *)buf,"left_pwm:%.2f    ",left_pwm);SHOW(0,4,buf);
	 //ִ�д���
	 //Steer_Test();
}

void Flag_UI(void)
{
	static signed char cur_pos=0;  
	 static signed char unit=1;
		_STATIC_DESK_HEAD(_desk1)
	 //�ž�̬��ʾ���ݣ�
		Cursor_Pos(CursorPosition,cur_pos);
		sprintf((char *)buf,"<Flag>");SHOW(0,0,buf);
		sprintf((char *)buf,"Task1: ");SHOW(8,1,buf);
		sprintf((char *)buf,"Task2: ");SHOW(8,2,buf);
		sprintf((char *)buf,"Task3: ");SHOW(8,3,buf);
		sprintf((char *)buf,"Task4: ");SHOW(8,4,buf);
		sprintf((char *)buf,"Task5: ");SHOW(8,5,buf);
		sprintf((char *)buf,"Task6: ");SHOW(8,6,buf);
		Cursor_Pos(CursorPosition,cur_pos);
		_STATIC_DESK_END(_desk1)
	 //�Ŷ�̬��ʾ���ݣ�
		
		if(config_flag == 0 && UP_IN)
        {
						cur_pos--;
						Round_Param(&cur_pos,0,13);
						Cursor_Pos(CursorPosition,cur_pos);
        }
        if(config_flag == 0 && DOWN_IN)
        {
						cur_pos++;
						Round_Param(&cur_pos,0,13);
						Cursor_Pos(CursorPosition,cur_pos);
        }
		if(MID_IN)
        {		
						if(config_flag==0)
							SHOW_CLEAR(0x00);
						else
						{	
							SHOW_CLEAR(0x00);
							sprintf((char *)buf,"<Flag>");SHOW(0,0,buf);
							sprintf((char *)buf,"Task1: ");SHOW(8,1,buf);
							sprintf((char *)buf,"Task2: ");SHOW(8,2,buf);
							sprintf((char *)buf,"Task3: ");SHOW(8,3,buf);
							sprintf((char *)buf,"Task4: ");SHOW(8,4,buf);
							sprintf((char *)buf,"Task5: ");SHOW(8,5,buf);
							sprintf((char *)buf,"Task6: ");SHOW(8,6,buf);
							Cursor_Pos(CursorPosition,cur_pos);
							flag_task=0;
							pause_flag=1;
						}
						config_flag=1-config_flag;
						
//					sprintf((char *)buf,"%d",config_flag);SHOW(120,0,buf);
        }
		
		if(config_flag)
		{
				switch(cur_pos)
				{
					case 0:
						SHOW(0,0,"task1"); 
					if(KEY1_IN)
					{
						SHOW(0,1,"Go1!");
					
						flag_task=1;
						sprintf((char *)buf,"flag1:%d ",flag_task);SHOW(0,2,buf);
					}
					break;
					case 1:
						SHOW(0,0,"task2"); 
						if(KEY1_IN)
						{
							SHOW(0,1,"Go2!");
							
							flag_task=2;
							float_yaw_duty=810;
							float_pitch_duty=440;
							sprintf((char *)buf,"flag2:%d ",flag_task);SHOW(0,2,buf);
						}
						break;
					case 2:
						SHOW(0,0,"task3");
					
						if(flag_task==0)
						{
							cloud_yaw_duty=zuobiao[1][0];
							cloud_pitch_duty=zuobiao[1][1];
							Steer_Y_P(cloud_yaw_duty,cloud_pitch_duty);
						}
						if(KEY1_IN)
						{
							SHOW(0,1,"Go3!");
							flag_task=3;
							
							float_yaw_duty=zuobiao[1][0];
							float_pitch_duty=zuobiao[1][1];
							sprintf((char *)buf,"flag3:%d ",flag_task);SHOW(0,2,buf);
						}		
						if(UP_IN)
							pause_flag=1-pause_flag;
						break;
					case 3:
						SHOW(0,0,"task4");
					
						if(KEY1_IN)
						{
							SHOW(0,1,"Go4!");
							flag_task=4;
							
							sprintf((char *)buf,"flag4:%d ",flag_task);SHOW(0,2,buf);
						}
						break;
					case 4:
						SHOW(0,0,"task5");
					
						if(flag_task==0)
						{
							renwusanj8_yaw=zuobiao[1][0];
							renwusanj8_pitch=zuobiao[1][1];
							Steer_Y_P(renwusanj8_yaw,renwusanj8_pitch);
						}
						
						if(KEY1_IN)
						{
							SHOW(0,1,"Go5!");
							flag_task=5;
//							for(i=0;i<50;i++)
							uart_putchar(UART_1,'s');
//							apply_point();
							R(0);G(0);B(1);
							sprintf((char *)buf,"flag5:%d ",flag_task);SHOW(0,2,buf);
						}
						break;
					case 5:
						if(flag_task==0)
						{
							j8renwusi_yaw=zuobiao[4][0];
							j8renwusi_pitch=zuobiao[4][1];
							Steer_Y_P((int)j8renwusi_yaw,(int)j8renwusi_pitch);
						}
						
						SHOW(0,0,"task6");
						if(KEY1_IN)
						{
							SHOW(0,1,"Go6!");
							flag_task=6;
							apply_point();
							R(0);G(0);B(1);
							delay_ms(2000);
							sprintf((char *)buf,"flag6:%d ",flag_task);SHOW(0,2,buf);
						}
						break;
					default: break;
				}
	
		}
}
void apply_point(void)
{
	uart_putchar(UART_1,'s');
}
void Steer_Test(void)
{
	static signed char unit=1;
		_STATIC_DESK_HEAD(_desk2)
	 //�ž�̬��ʾ���ݣ�
		sprintf((char *)buf,"<Steer Test>");SHOW(0,0,buf);
		sprintf((char *)buf,"cloud_yaw:",cloud_yaw_duty);SHOW(0,1,buf);
		sprintf((char *)buf,"cloud_pitch:",cloud_pitch_duty);SHOW(0,2,buf);
		sprintf((char *)buf,"the_point:");SHOW(0,3,buf);
	 _STATIC_DESK_END(_desk2)
	 //�Ŷ�̬��ʾ���ݣ�
		sprintf((char *)buf,"%d ",cloud_yaw_duty);SHOW(60,1,buf);
		sprintf((char *)buf,"%d ",cloud_pitch_duty);SHOW(72,2,buf);
		sprintf((char *)buf,"%d ",select_point);SHOW(72,3,buf);
//		sprintf((char *)buf,"%4.0f %4.0f",zuobiao[0][0],zuobiao[0][1]);SHOW(0,4,buf);
//		sprintf((char *)buf,"%4.0f %4.0f",zuobiao[1][0],zuobiao[1][1]);SHOW(0,5,buf);
//		sprintf((char *)buf,"%4.0f %4.0f",zuobiao[2][0],zuobiao[2][1]);SHOW(0,6,buf);
//		sprintf((char *)buf,"%4.0f %4.0f",zuobiao[3][0],zuobiao[3][1]);SHOW(0,7,buf);
	 //ִ�д���
	if(_now_mod==2&&KEY1_IN)
	{
		steer_flag=1-steer_flag;
	}
	if(steer_flag==1)		
	{
//		Steer_Control();
		if(LEFT_IN)
		{
			cloud_yaw_duty+=UNIT_ROUND[unit];;
			pwm_duty(CLOUD_YAW_Pin,cloud_yaw_duty);
		}
		if(RIGHT_IN)
		{
			cloud_yaw_duty-=UNIT_ROUND[unit];;
			pwm_duty(CLOUD_YAW_Pin,cloud_yaw_duty);
		}
		if(UP_IN)
		{
			cloud_pitch_duty+=UNIT_ROUND[unit];;
			pwm_duty(CLOUD_PITCH_Pin,cloud_pitch_duty);
		}
		if(DOWN_IN)
		{
			cloud_pitch_duty-=UNIT_ROUND[unit];;
			pwm_duty(CLOUD_PITCH_Pin,cloud_pitch_duty);
		}
	}
	if(MID_IN)
    {
		config_flag=1-config_flag;
		sprintf((char *)buf,"%d",config_flag);SHOW(120,0,buf);
	}
	if((config_flag!=0)&&(RIGHT_IN))  {unit++;Round_Param(&unit,0,2);SHOW(96,0,SHOW_UNIT[unit]);}
	if((config_flag!=0)&&(LEFT_IN))  {unit--;Round_Param(&unit,0,2);SHOW(96,0,SHOW_UNIT[unit]);}

}

void Sensor_Test(void)
{
		static signed char cur_pos=0; 
		static signed char unit=0;
		_STATIC_DESK_HEAD(_desk3)
	 //�ž�̬��ʾ���ݣ�
		sprintf((char *)buf,"<Position Test>");SHOW(0,0,buf);
		sprintf((char *)buf,"MID:");SHOW(8,1,buf);
		sprintf((char *)buf,"LUP:");SHOW(8,3,buf);
		sprintf((char *)buf,"RUP:");SHOW(8,5,buf);	
		sprintf((char *)buf,"RD:");SHOW(72,1,buf);
		sprintf((char *)buf,"LD:");SHOW(72,3,buf);	
		Cursor_Pos(CursorPosition,cur_pos);
	 _STATIC_DESK_END(_desk3)
	 //�Ŷ�̬��ʾ���ݣ�
		sprintf((char *)buf,"%d",zuobiao[0][0]);SHOW(40,1,buf);
		sprintf((char *)buf,"%d",zuobiao[0][1]);SHOW(40,2,buf);
		sprintf((char *)buf,"%d",zuobiao[1][0]);SHOW(40,3,buf);	
		sprintf((char *)buf,"%d",zuobiao[1][1]);SHOW(40,4,buf);	
		sprintf((char *)buf,"%d",zuobiao[2][0]);SHOW(40,5,buf);	
		sprintf((char *)buf,"%d",zuobiao[2][1]);SHOW(40,6,buf);	

		sprintf((char *)buf,"%d",zuobiao[3][0]);SHOW(96,1,buf);	
		sprintf((char *)buf,"%d",zuobiao[3][1]);SHOW(96,2,buf);	
		sprintf((char *)buf,"%d",zuobiao[4][0]);SHOW(96,3,buf);	
		sprintf((char *)buf,"%d",zuobiao[4][1]);SHOW(96,4,buf);	
			
		if(config_flag == 0 && UP_IN)
        {
						cur_pos--;
						Round_Param(&cur_pos,0,13);
						Cursor_Pos(CursorPosition,cur_pos);
        }
        if(config_flag == 0 && DOWN_IN)
        {
						cur_pos++;
						Round_Param(&cur_pos,0,13);
						Cursor_Pos(CursorPosition,cur_pos);
        }
		if(MID_IN)
        {
					config_flag=1-config_flag;
					sprintf((char *)buf,"%d",config_flag);SHOW(120,0,buf);
					SHOW(96,0,SHOW_UNIT[unit]);
        }
		if((config_flag!=0)&&(RIGHT_IN))  {unit++;Round_Param(&unit,0,2);SHOW(96,0,SHOW_UNIT[unit]);}
		if((config_flag!=0)&&(LEFT_IN))  {unit--;Round_Param(&unit,0,2);SHOW(96,0,SHOW_UNIT[unit]);}
		
		if(config_flag)
		{			
			if(UP_IN)
			{
				switch(cur_pos)
				{
					case 0:
						zuobiao[0][0]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[0][0],zuobiao[0][1]);break;
					case 1:
						zuobiao[0][1]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[0][0],zuobiao[0][1]);break;
					case 2:
						zuobiao[1][0]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[1][0],zuobiao[1][1]);break;
					case 3:
						zuobiao[1][1]+=UNIT_ROUND[unit];
						UI_YP(zuobiao[1][0],zuobiao[1][1]);break;
					case 4:
						zuobiao[2][0]+=UNIT_ROUND[unit];
						UI_YP(zuobiao[2][0],zuobiao[2][1]);break;
					case 5:
						zuobiao[2][1]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[2][0],zuobiao[2][1]);break;
					case 7:
						zuobiao[3][0]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[3][0],zuobiao[3][1]);break;
					case 8:
						zuobiao[3][1]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[3][0],zuobiao[3][1]);break;
					case 9:
						zuobiao[4][0]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[4][0],zuobiao[4][1]);break;
					case 10:
						zuobiao[4][1]+=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[4][0],zuobiao[4][1]);break;

					
					default: break;
				}
			}
			
			if(DOWN_IN)
			{
				switch(cur_pos)
				{
					case 0:
						zuobiao[0][0]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[0][0],zuobiao[0][1]);break;
					case 1:
						zuobiao[0][1]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[0][0],zuobiao[0][1]);break;
					case 2:
						zuobiao[1][0]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[1][0],zuobiao[1][1]);break;
					case 3:
						zuobiao[1][1]-=UNIT_ROUND[unit];
						UI_YP(zuobiao[1][0],zuobiao[1][1]);break;
					case 4:
						zuobiao[2][0]-=UNIT_ROUND[unit];
						UI_YP(zuobiao[2][0],zuobiao[2][1]);break;
					case 5:
						zuobiao[2][1]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[2][0],zuobiao[2][1]);break;
					case 7:
						zuobiao[3][0]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[3][0],zuobiao[3][1]);break;
					case 8:
						zuobiao[3][1]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[3][0],zuobiao[3][1]);break;
					case 9:
						zuobiao[4][0]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[4][0],zuobiao[4][1]);break;
					case 10:
						zuobiao[4][1]-=UNIT_ROUND[unit]; 
						UI_YP(zuobiao[4][0],zuobiao[4][1]);break;					
					default: break;
				}
			}
			
			AT_Backups(1);
		}
}



void Adjust_Parameter_UI(void)
{
	 static signed char cur_pos=0; 
	 static signed char unit=1;
		_STATIC_DESK_HEAD(_desk5)
	 //�ž�̬��ʾ���ݣ�
		sprintf((char *)buf,"<task3>");SHOW(0,0,buf);
		sprintf((char *)buf,"MID:");SHOW(8,1,buf);
		sprintf((char *)buf,"LUP:");SHOW(8,3,buf);
		sprintf((char *)buf,"RUP:");SHOW(8,5,buf);	
		sprintf((char *)buf,"RD:");SHOW(72,1,buf);
		sprintf((char *)buf,"LD:");SHOW(72,3,buf);
		Cursor_Pos(CursorPosition,cur_pos);
	 _STATIC_DESK_END(_desk5)
	 //�Ŷ�̬��ʾ���ݣ�
		sprintf((char *)buf,"%d",task3[0][0]);SHOW(40,1,buf);
		sprintf((char *)buf,"%d",task3[0][1]);SHOW(40,2,buf);
		sprintf((char *)buf,"%d",task3[1][0]);SHOW(40,3,buf);	
		sprintf((char *)buf,"%d",task3[1][1]);SHOW(40,4,buf);	
		sprintf((char *)buf,"%d",task3[2][0]);SHOW(40,5,buf);	
		sprintf((char *)buf,"%d",task3[2][1]);SHOW(40,6,buf);	

		sprintf((char *)buf,"%d",task3[3][0]);SHOW(96,1,buf);	
		sprintf((char *)buf,"%d",task3[3][1]);SHOW(96,2,buf);	
		sprintf((char *)buf,"%d",task3[4][0]);SHOW(96,3,buf);	
		sprintf((char *)buf,"%d",task3[4][1]);SHOW(96,4,buf);	
	
		if(config_flag == 0 && UP_IN)
        {
						cur_pos--;
						Round_Param(&cur_pos,0,13);
						Cursor_Pos(CursorPosition,cur_pos);
        }
        if(config_flag == 0 && DOWN_IN)
        {
						cur_pos++;
						Round_Param(&cur_pos,0,13);
						Cursor_Pos(CursorPosition,cur_pos);
        }
		if(MID_IN)
        {
					config_flag=1-config_flag;
					sprintf((char *)buf,"%d",config_flag);SHOW(120,0,buf);
					SHOW(96,0,SHOW_UNIT[unit]);
        }
		if((config_flag!=0)&&(RIGHT_IN))  {unit++;Round_Param(&unit,0,2);SHOW(96,0,SHOW_UNIT[unit]);}
		if((config_flag!=0)&&(LEFT_IN))  {unit--;Round_Param(&unit,0,2);SHOW(96,0,SHOW_UNIT[unit]);}
		
		if(config_flag)
		{
			if(UP_IN)
			{
				switch(cur_pos)
				{
					case 0:
						task3[0][0]+=UNIT_ROUND[unit]; 
						UI_YP(task3[0][0],task3[0][1]);break;
					case 1:
						task3[0][1]+=UNIT_ROUND[unit]; 
						UI_YP(task3[0][0],task3[0][1]);break;
					case 2:
						task3[1][0]+=UNIT_ROUND[unit]; 
						UI_YP(task3[1][0],task3[1][1]);break;
					case 3:
						task3[1][1]+=UNIT_ROUND[unit];
						UI_YP(task3[1][0],task3[1][1]);break;
					case 4:
						task3[2][0]+=UNIT_ROUND[unit];
						UI_YP(task3[2][0],task3[2][1]);break;
					case 5:
						task3[2][1]+=UNIT_ROUND[unit]; 
						UI_YP(task3[2][0],task3[2][1]);break;
					case 7:
						task3[3][0]+=UNIT_ROUND[unit]; 
						UI_YP(task3[3][0],task3[3][1]);break;
					case 8:
						task3[3][1]+=UNIT_ROUND[unit]; 
						UI_YP(task3[3][0],task3[3][1]);break;
					case 9:
						task3[4][0]+=UNIT_ROUND[unit]; 
						UI_YP(task3[4][0],task3[4][1]);break;
					case 10:
						task3[4][1]+=UNIT_ROUND[unit]; 
						UI_YP(task3[4][0],task3[4][1]);break;

					
					default: break;
				}
			}
			
			if(DOWN_IN)
			{
				switch(cur_pos)
				{
					case 0:
						task3[0][0]-=UNIT_ROUND[unit]; 
						UI_YP(task3[0][0],task3[0][1]);break;
					case 1:
						task3[0][1]-=UNIT_ROUND[unit]; 
						UI_YP(task3[0][0],task3[0][1]);break;
					case 2:
						task3[1][0]-=UNIT_ROUND[unit]; 
						UI_YP(task3[1][0],task3[1][1]);break;
					case 3:
						task3[1][1]-=UNIT_ROUND[unit];
						UI_YP(task3[1][0],task3[1][1]);break;
					case 4:
						task3[2][0]-=UNIT_ROUND[unit];
						UI_YP(task3[2][0],task3[2][1]);break;
					case 5:
						task3[2][1]-=UNIT_ROUND[unit]; 
						UI_YP(task3[2][0],task3[2][1]);break;
					case 7:
						task3[3][0]-=UNIT_ROUND[unit]; 
						UI_YP(task3[3][0],task3[3][1]);break;
					case 8:
						task3[3][1]-=UNIT_ROUND[unit]; 
						UI_YP(task3[3][0],task3[3][1]);break;
					case 9:
						task3[4][0]-=UNIT_ROUND[unit]; 
						UI_YP(task3[4][0],task3[4][1]);break;
					case 10:
						task3[4][1]-=UNIT_ROUND[unit]; 
						UI_YP(task3[4][0],task3[4][1]);break;
					
					default: break;
				}
			}
			AT_Backups(1);
		}

		
}

void Check_and_Change_Desk(void)
{
		if(_MOD == _desk1) //�ֲ�ͬ����
		{
			Flag_UI();
		}
		else if(_MOD == _desk2)
		{
			Steer_Test();
		}
		else if(_MOD == _desk3)
		{
			Sensor_Test();
		}
		else if(_MOD == _desk4)
		{
			Main_UI();
		}
		else if(_MOD == _desk5)
		{
			Adjust_Parameter_UI();
		}
}

/*
//	if(steer_flag==0&&UP_IN)
//	{
//		select_point++;
//		if(select_point>=5)
//			select_point=0;
//	}
//	if(steer_flag==0&&DOWN_IN)
//	{
//		select_point--;
//		if(select_point<0)
//			select_point=4;
//	}
//	if(KEY1_IN)
//	{
//		switch(select_point)
//		{
//			case 0:
//				break;
//			case 1:
//				zuobiao[0][0]=cloud_yaw_duty;
//				zuobiao[0][1]=cloud_pitch_duty;
//				sprintf((char *)buf,"%4.0f %4.0f",zuobiao[0][0],zuobiao[0][1]);SHOW(0,4,buf);
//				break;
//			case 2:
//				zuobiao[1][0]=cloud_yaw_duty;
//				zuobiao[1][1]=cloud_pitch_duty;
//				sprintf((char *)buf,"%4.0f %4.0f",zuobiao[1][0],zuobiao[1][1]);SHOW(0,5,buf);
//				break;
//			case 3:
//				zuobiao[2][0]=cloud_yaw_duty;
//				zuobiao[2][1]=cloud_pitch_duty;
//				sprintf((char *)buf,"%4.0f %4.0f",zuobiao[2][0],zuobiao[2][1]);SHOW(0,6,buf);
//				break;
//			case 4:
//				zuobiao[3][0]=cloud_yaw_duty;
//				zuobiao[3][1]=cloud_pitch_duty;
//				sprintf((char *)buf,"%4.0f %4.0f",zuobiao[3][0],zuobiao[3][1]);SHOW(0,7,buf);
//				break;
//			default: break;
//		
//		}
//	}
*/